<?php
class Logon extends CI_Model {
	
	function __construct() {
		parent::__construct ();
	}
	//logoff
	public function logoff(){
		$this->session->sess_destroy();
		echo '<script >
		parent.location="/index.php/admin/home/logon";
		</script>';
	//	header("location:/index.php/admin/home/logon");
	}
	//login
	public function logon($user='',$pass='', $verify=''){
		$s_v_code = $this->session->userdata('verification_code'); 
		$error = '';
		if($user && $pass && $verify){
			$users = $this->config->item('administrators');
			$pass = strtoupper(md5($pass));
			$logintime = date('Y-m-d H:i:s');
			if($verify == $s_v_code){
				if(!empty($users[$pass]) && $users[$pass] == $user){
					$this->load->database();
					$this->session->set_userdata(array('lz_chinese_user'=> array('lz_u'=>$user,'lz_time'=>$logintime)));
					$this->load->helper('functions');
					$ip = getClientIP();
					$sql = "insert into lz_loginrecord(`username`,`logintime`,`loginip`)values('{$user}','{$logintime}', '{$ip}')";
					$this->db->query($sql);
					header("location:/index.php/admin");
				}else{
					$error = '帐号和密码不匹配，请联系管理员';
				}
			}else{
				$error = '验证码输入错误';
			}
		}
		
		$data['site_title'] = $this->config->item('site_title');
		$data['error'] = $error;
		$this->load->vars($data);
	}
	function __destruct() {
	
	}
}
?>